//
//  CommenWebViewController.m
//  DDFish
//
//  Created by 糖otk on 2017/8/16.
//  Copyright © 2017年 Burining. All rights reserved.
//

#import "CommenWebViewController.h"
#import <WebKit/WebKit.h>
#import "PPNetworkHelper.h"

#import "NoWLView.h"

@interface CommenWebViewController ()

@property (nonatomic, strong) WKWebView *wkWebView;
@property (nonatomic, strong) NSMutableURLRequest *request;

@property(nonatomic,strong)NoWLView * nosetView;

@end

@implementation CommenWebViewController


- (WKWebView *)wkWebView {
    if (!_wkWebView) {
        _wkWebView = [[WKWebView alloc] init];
        _wkWebView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight-64);
        
        _wkWebView.scrollView.backgroundColor = MainBackGroudColor;
    }
    return _wkWebView;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = MainBackGroudColor;

     self.automaticallyAdjustsScrollViewInsets = false;
    [self loadCreat];

}

-(NoWLView *)nosetView{
    
    if(_nosetView == nil){
        
        _nosetView = [NoWLView NoSetView];
        
        _nosetView.frame = CGRectMake(0, 0, self.view.width,  ScreenHeight-108);
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(loadCreat)];
        
        [_nosetView addGestureRecognizer:tap];
    }
    
    return _nosetView;
    
}

-(void)loadCreat{
    
    if (![PPNetworkHelper currentNetworkStatus]) {
//        [MBProgressHUD showOnlyTextToView:AppWindow title:NetWorkError];
        
        [self.wkWebView removeFromSuperview];
        
        [self.view addSubview:self.nosetView];
      
        
    }else{
        [self.nosetView removeFromSuperview];
       
        [self addChirldSubviews];
    }

}

- (void)addChirldSubviews {
    [self.view addSubview: self.wkWebView];
 
    NSLog(@"%@",self.tempString);
    NSURL *url = [NSURL URLWithString:self.tempString];
    self.request = [NSMutableURLRequest requestWithURL:url];
    [self.wkWebView loadRequest:self.request];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)dealloc {
    NSLog(@"dealloc-webview");
}
@end
